// pages/productDetail/productDetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerUrls: [ //轮播图的图片
      {
        url: '/assets/coffice_detail_01.jpg',
        linkUrl: ''
      },
      {
        url: '/assets/coffice_detail_02.jpg',
        linkUrl: ''
      },
      {
        url: '/assets/coffice_detail_03.jpg',
        linkUrl: ''
      }
    ],
    imgheights: 280,

    productDetail: {
      moreDetails:["/assets/pro_detail_01.png","/assets/pro_detail_02.png","/assets/pro_detail_03.png"],
      specifications: [{
        id: "1",
        specName: "杯型",
        choices: [{
          id: "1",
          name: "大杯",
          tips: "推荐",
          selected:1
        }, {
          id: "2",
          name: "中杯",
          tips: "",
          selected:0
        }]
      }, {
        id: "2",
        specName: "温度",
        choices: [{
          id: "1",
          name: "冰",
          tips: "推荐",
          selected:1
        }, {
          id: "2",
          name: "热",
          tips: "",
          selected:0
        }]
      }, {
        id: "3",
        specName: "糖度",
        choices: [{
          id: "1",
          name: "不另外家庭",
          tips: "推荐|微甜",
          selected:1
        }, {
          id: "2",
          name: "半糖",
          tips: "",
          selected:0
        }, {
          id: "3",
          name: "标准糖",
          tips: "",
          selected:0
        }]
      }]
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  // 选择规格
  selectedSpec(item){
    let itemId=item.currentTarget.dataset.itemid;
    let cid=item.currentTarget.dataset.cid;
    var detail=this.data.productDetail;
    detail.specifications.forEach(function(item){
      if(itemId==item.id){
          for(var i in item.choices){
              var c=item.choices[i];
              c.selected=0;
              if(cid==c.id){
                 c.selected=1;
                 console.log("sdfsdf")
              }
          }
      }
    })
    this.setData({
      productDetail:detail
    })
  },
  //返回上一页
  gobackPage(){
    wx.navigateBack();
  }
})